home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / RCSC.ZIP / DEMO86 / MCONSOLE.C < prev    next >
C/C++ Source or Header  |  1997-01-12  |  993b  |  44 lines

  1. #include <stdio.h>
  2.  
  3. /* monitor data */
  4. static CONDITION conready;    /* console ready condition variable */
  5. static CONDITION msgavail;    /* message available condition variable */
  6. static int busy;        /* buffer inuse invariant */
  7. static char buffer[128];    /* monitor's message buffer */
  8.  
  9. /* console monitor initialization */
  10. void monitor mconsole()
  11. {
  12.     printf("Initializing console monitor...\n");
  13. }
  14.  
  15. /* monitor entry to send message to console */
  16. void entry Send(msg)
  17. char *msg;
  18. {
  19.     /* wait till buffer is not in use */
  20.     if (busy) 
  21.         Wait(&conready);
  22.  
  23.     /* copy message to local buffer and wake up console */
  24.     strcpy(buffer, msg);
  25.     busy = 1;
  26.     Signal(&msgavail);
  27. }
  28.  
  29. /* monitor entry for console to get message */
  30. entry GetMsg(msg)
  31. char *msg;
  32. {
  33.     /* wait till message is available */
  34.     if (!busy)
  35.         Wait(&msgavail);
  36.  
  37.     /* copy message to caller's buffer and wake up any task 
  38.         waiting to deliver a message */
  39.     strcpy(msg, buffer);
  40.     busy = 0;
  41.     Signal(&conready);
  42. }
  43.  
  44.